1 module hip.jni.android.native_activity; 2 version(Android): 3 /* 4 * Copyright (C) 2010 The Android Open Source Project 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 /** 20 * @addtogroup NativeActivity Native Activity 21 * @{ 22 */ 23 24 /** 25 * @file native_activity.h 26 */ 27 28 import core.stdc.stdint; 29 import hip.jni.jni; 30 import hip.jni.android.rect; 31 import hip.jni.android.asset_manager; 32 import hip.jni.android.native_window; 33 import hip.jni.android.input; 34 35 extern(C): 36 37 38 /** 39 * This structure defines the native side of an android.app.NativeActivity. 40 * It is created by the framework, and handed to the application's native 41 * code as it is being launched. 42 */ 43 struct ANativeActivity { 44 /** 45 * Pointer to the callback function table of the native application. 46 * You can set the functions here to your own callbacks. The callbacks 47 * pointer itself here should not be changed; it is allocated and managed 48 * for you by the framework. 49 */ 50 ANativeActivityCallbacks* callbacks; 51 52 /** 53 * The global handle on the process's Java VM. 54 */ 55 JavaVM* vm; 56 57 /** 58 * JNI context for the main thread of the app. Note that this field 59 * can ONLY be used from the main thread of the process; that is, the 60 * thread that calls into the ANativeActivityCallbacks. 61 */ 62 JNIEnv* env; 63 64 /** 65 * The NativeActivity object handle. 66 * 67 * IMPORTANT NOTE: This member is mis-named. It should really be named 68 * 'activity' instead of 'clazz', since it's a reference to the 69 * NativeActivity instance created by the system for you. 70 * 71 * We unfortunately cannot change this without breaking NDK 72 * source-compatibility. 73 */ 74 jobject clazz; 75 76 /** 77 * Path to this application's internal data directory. 78 */ 79 const char* internalDataPath; 80 81 /** 82 * Path to this application's external (removable/mountable) data directory. 83 */ 84 const char* externalDataPath; 85 86 /** 87 * The platform's SDK version code. 88 */ 89 int32_t sdkVersion; 90 91 /** 92 * This is the native instance of the application. It is not used by 93 * the framework, but can be set by the application to its own instance 94 * state. 95 */ 96 void* instance; 97 98 /** 99 * Pointer to the Asset Manager instance for the application. The application 100 * uses this to access binary assets bundled inside its own .apk file. 101 */ 102 AAssetManager* assetManager; 103 104 /** 105 * Available starting with Honeycomb: path to the directory containing 106 * the application's OBB files (if any). If the app doesn't have any 107 * OBB files, this directory may not exist. 108 */ 109 const char* obbPath; 110 } 111 112 /** 113 * These are the callbacks the framework makes into a native application. 114 * All of these callbacks happen on the main thread of the application. 115 * By default, all callbacks are NULL; set to a pointer to your own function 116 * to have it called. 117 */ 118 struct ANativeActivityCallbacks { 119 /** 120 * NativeActivity has started. See Java documentation for Activity.onStart() 121 * for more information. 122 */ 123 void function(ANativeActivity* activity) onStart; 124 125 /** 126 * NativeActivity has resumed. See Java documentation for Activity.onResume() 127 * for more information. 128 */ 129 void function(ANativeActivity* activity) onResume; 130 131 /** 132 * Framework is asking NativeActivity to save its current instance state. 133 * See Java documentation for Activity.onSaveInstanceState() for more 134 * information. The returned pointer needs to be created with malloc(); 135 * the framework will call free() on it for you. You also must fill in 136 * outSize with the number of bytes in the allocation. Note that the 137 * saved state will be persisted, so it can not contain any active 138 * entities (pointers to memory, file descriptors, etc). 139 */ 140 void* function(ANativeActivity* activity, size_t* outSize) onSaveInstanceState; 141 142 /** 143 * NativeActivity has paused. See Java documentation for Activity.onPause() 144 * for more information. 145 */ 146 void function(ANativeActivity* activity) onPause; 147 148 /** 149 * NativeActivity has stopped. See Java documentation for Activity.onStop() 150 * for more information. 151 */ 152 void function(ANativeActivity* activity) onStop; 153 154 /** 155 * NativeActivity is being destroyed. See Java documentation for Activity.onDestroy() 156 * for more information. 157 */ 158 void function(ANativeActivity* activity) onDestroy; 159 160 /** 161 * Focus has changed in this NativeActivity's window. This is often used, 162 * for example, to pause a game when it loses input focus. 163 */ 164 void function(ANativeActivity* activity, int hasFocus) onWindowFocusChanged; 165 166 /** 167 * The drawing window for this native activity has been created. You 168 * can use the given native window object to start drawing. 169 */ 170 void function(ANativeActivity* activity, ANativeWindow* window) onNativeWindowCreated; 171 172 /** 173 * The drawing window for this native activity has been resized. You should 174 * retrieve the new size from the window and ensure that your rendering in 175 * it now matches. 176 */ 177 void function(ANativeActivity* activity, ANativeWindow* window) onNativeWindowResized; 178 179 /** 180 * The drawing window for this native activity needs to be redrawn. To avoid 181 * transient artifacts during screen changes (such resizing after rotation), 182 * applications should not return from this function until they have finished 183 * drawing their window in its current state. 184 */ 185 void function(ANativeActivity* activity, ANativeWindow* window) onNativeWindowRedrawNeeded; 186 187 /** 188 * The drawing window for this native activity is going to be destroyed. 189 * You MUST ensure that you do not touch the window object after returning 190 * from this function: in the common case of drawing to the window from 191 * another thread, that means the implementation of this callback must 192 * properly synchronize with the other thread to stop its drawing before 193 * returning from here. 194 */ 195 void function(ANativeActivity* activity, ANativeWindow* window) onNativeWindowDestroyed; 196 197 /** 198 * The input queue for this native activity's window has been created. 199 * You can use the given input queue to start retrieving input events. 200 */ 201 void function(ANativeActivity* activity, AInputQueue* queue) onInputQueueCreated; 202 203 /** 204 * The input queue for this native activity's window is being destroyed. 205 * You should no longer try to reference this object upon returning from this 206 * function. 207 */ 208 void function(ANativeActivity* activity, AInputQueue* queue) onInputQueueDestroyed; 209 210 /** 211 * The rectangle in the window in which content should be placed has changed. 212 */ 213 void function(ANativeActivity* activity, const ARect* rect) onContentRectChanged; 214 215 /** 216 * The current device AConfiguration has changed. The new configuration can 217 * be retrieved from assetManager. 218 */ 219 void function(ANativeActivity* activity) onConfigurationChanged; 220 221 /** 222 * The system is running low on memory. Use this callback to release 223 * resources you do not need, to help the system avoid killing more 224 * important processes. 225 */ 226 void function(ANativeActivity* activity) onLowMemory; 227 } 228 229 /** 230 * This is the function that must be in the native code to instantiate the 231 * application's native activity. It is called with the activity instance (see 232 * above); if the code is being instantiated from a previously saved instance, 233 * the savedState will be non-NULL and point to the saved data. You must make 234 * any copy of this data you need -- it will be released after you return from 235 * this function. 236 */ 237 alias ANativeActivity_createFunc = void function(ANativeActivity* activity, 238 void* savedState, size_t savedStateSize); 239 240 /** 241 * The name of the function that NativeInstance looks for when launching its 242 * native code. This is the default function that is used, you can specify 243 * "android.app.func_name" string meta-data in your manifest to use a different 244 * function. 245 */ 246 extern ANativeActivity_createFunc ANativeActivity_onCreate; 247 248 /** 249 * Finish the given activity. Its finish() method will be called, causing it 250 * to be stopped and destroyed. Note that this method can be called from 251 * *any* thread; it will send a message to the main thread of the process 252 * where the Java finish call will take place. 253 */ 254 void ANativeActivity_finish(ANativeActivity* activity); 255 256 /** 257 * Change the window format of the given activity. Calls getWindow().setFormat() 258 * of the given activity. Note that this method can be called from 259 * *any* thread; it will send a message to the main thread of the process 260 * where the Java finish call will take place. 261 */ 262 void ANativeActivity_setWindowFormat(ANativeActivity* activity, int32_t format); 263 264 /** 265 * Change the window flags of the given activity. Calls getWindow().setFlags() 266 * of the given activity. Note that this method can be called from 267 * *any* thread; it will send a message to the main thread of the process 268 * where the Java finish call will take place. See window.h for flag constants. 269 */ 270 void ANativeActivity_setWindowFlags(ANativeActivity* activity, 271 uint32_t addFlags, uint32_t removeFlags); 272 273 /** 274 * Flags for ANativeActivity_showSoftInput; see the Java InputMethodManager 275 * API for documentation. 276 */ 277 enum { 278 /** 279 * Implicit request to show the input window, not as the result 280 * of a direct request by the user. 281 */ 282 ANATIVEACTIVITY_SHOW_SOFT_INPUT_IMPLICIT = 0x0001, 283 284 /** 285 * The user has forced the input method open (such as by 286 * long-pressing menu) so it should not be closed until they 287 * explicitly do so. 288 */ 289 ANATIVEACTIVITY_SHOW_SOFT_INPUT_FORCED = 0x0002, 290 } 291 292 /** 293 * Show the IME while in the given activity. Calls InputMethodManager.showSoftInput() 294 * for the given activity. Note that this method can be called from 295 * *any* thread; it will send a message to the main thread of the process 296 * where the Java finish call will take place. 297 */ 298 void ANativeActivity_showSoftInput(ANativeActivity* activity, uint32_t flags); 299 300 /** 301 * Flags for ANativeActivity_hideSoftInput; see the Java InputMethodManager 302 * API for documentation. 303 */ 304 enum { 305 /** 306 * The soft input window should only be hidden if it was not 307 * explicitly shown by the user. 308 */ 309 ANATIVEACTIVITY_HIDE_SOFT_INPUT_IMPLICIT_ONLY = 0x0001, 310 /** 311 * The soft input window should normally be hidden, unless it was 312 * originally shown with {@link ANATIVEACTIVITY_SHOW_SOFT_INPUT_FORCED}. 313 */ 314 ANATIVEACTIVITY_HIDE_SOFT_INPUT_NOT_ALWAYS = 0x0002, 315 }; 316 317 /** 318 * Hide the IME while in the given activity. Calls InputMethodManager.hideSoftInput() 319 * for the given activity. Note that this method can be called from 320 * *any* thread; it will send a message to the main thread of the process 321 * where the Java finish call will take place. 322 */ 323 void ANativeActivity_hideSoftInput(ANativeActivity* activity, uint32_t flags);